// Author: wsfuyibing <682805@qq.com>
// Date: 2025-06-12

package kind

type ClosedBy int

const (
	ClosedByNot     ClosedBy = 0 // 未撤销.
	ClosedByTimeout ClosedBy = 1 // 超时未处理(如订单30分未付款)
	ClosedByBuyer   ClosedBy = 2 // 由买家(钓友)
	ClosedBySaler   ClosedBy = 3 // 由卖家(钓卖管理员)
)

var (
	closedByTexts = map[ClosedBy]string{
		ClosedByNot:     "未撤销",
		ClosedByTimeout: "超时",
		ClosedByBuyer:   "买家",
		ClosedBySaler:   "卖家",
	}

	closedByFlags = map[ClosedBy]string{
		ClosedByNot:     "not",
		ClosedByTimeout: "timeout",
		ClosedByBuyer:   "buyer",
		ClosedBySaler:   "saler",
	}
)

func ClosedByDict() []map[string]any {
	var res = make([]map[string]any, 0)
	for _, v := range []ClosedBy{
		ClosedByTimeout,
		ClosedByBuyer,
		ClosedBySaler,
	} {
		res = append(res, map[string]any{
			"Key":   v,
			"Value": v.Text(),
		})
	}
	return res
}

func (o ClosedBy) IsTimeout() bool { return o == ClosedByTimeout }
func (o ClosedBy) IsBuyer() bool   { return o == ClosedByBuyer }
func (o ClosedBy) IsSaler() bool   { return o == ClosedBySaler }

func (o ClosedBy) Flag() string {
	if str, ok := closedByFlags[o]; ok {
		return str
	}
	return ""
}

func (o ClosedBy) Text() string {
	if str, ok := closedByTexts[o]; ok {
		return str
	}
	return ""
}
